//
//  UITextField+DYCPlaceholder.m
//  DYCBaisi
//
//  Created by ChaoMac on 17/7/12.
//  Copyright © 2017年 Yachao. All rights reserved.
//

#import "UITextField+DYCPlaceholder.h"
#import <objc/message.h>
@implementation UITextField (DYCPlaceholder)

+ (void)load{
    // setPlaceholder
    Method setPlaceholderMethod = class_getInstanceMethod(self, @selector(setPlaceholder:));
    Method setDyc_PlaceholderMethod = class_getInstanceMethod(self, @selector(setDyc_Placeholder:));
    
    method_exchangeImplementations(setPlaceholderMethod, setDyc_PlaceholderMethod);}

- (void)setPlaceholderColor:(UIColor *)placeholderColor{
    
    // 给成员属性赋值 runtime给系统的类添加成员属性
    // 添加成员属性
    objc_setAssociatedObject(self, @"placeholderColor", placeholderColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    // 获取占位文字控件
    UILabel *placeholderLabel = [self valueForKey:@"placeholderLabel"];
    
    // 设置占位文字颜色
    placeholderLabel.textColor = placeholderColor;
}

- (UIColor *)placeholderColor{
    return objc_getAssociatedObject(self, @"placeholderColor");
}

- (void)setDyc_Placeholder:(NSString *)placeholder{
    // 设置占位文字
    // 设置占位文字颜色
    [self setDyc_Placeholder:placeholder];
    self.placeholderColor = self.placeholderColor;
}
@end
